package com.ibp.utils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URL;
import java.util.List;
import java.util.Properties;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class PropertyUtils
{
  private static Logger logger = LoggerFactory.getLogger(PropertyUtils.class);
  public Properties properties;
  private List<String> filePathes;
  private String path = super.getClass().getResource("/").getPath();

  @PostConstruct
  public void postInit()
  {
    logger.debug("init PropertyUtils ...");
    this.properties = new Properties();
    if (this.filePathes != null)
      for (String filename : this.filePathes)
        try
        {
          this.properties.load(new InputStreamReader(PropertyUtils.class.getResourceAsStream("/" + filename), "UTF-8"));
        } catch (IOException e) {
          logger.error("PropertyUtils加载配置文件出错:", e);
        }
  }

  public void load(String path)
  {
    try
    {
      this.properties.load(new InputStreamReader(Object.class.getResourceAsStream("/" + path), "UTF-8"));
    }
    catch (IOException e) {
      logger.error("PropertyUtils手动加载配置【" + path + "】出错:", e);
    }
  }

  public void setFilePathes(List<String> filePathes)
  {
    this.filePathes = filePathes;
  }
}